<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Patient Information</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: center;
        }
        .container {
            display: flex;
            align-items: center;
        }
        .left {
            flex: 1;
            padding: 20px;
        }
        .left img {
            max-width: 100%;
            height: auto;
        }
        .right {
            flex: 2;
            padding: 20px;
        }
        .patient-info {
            margin-bottom: 20px;
        }
        .edit-buttons {
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .edit-button {
            margin-right: 2px;
            padding: 10px 100px;
            font-size: 16px;
        }
        .upload-button {
            margin-top: 10px;
            padding: 10px 100px;
            font-size: 16px;
            background-color: #007bff;
            color: #fff;
            border: none;
            cursor: pointer;
        }
        table {
            border-collapse: collapse;
            width: 100%;
        }
        th, td {
            border: 1px solid #ccc;
            padding: 10px;
        }
    </style>
</head>
<body>
    <h1>医学影像PACS</h1>
    <div class="container">
        <div class="left">
            <img id="patient-image" src="/static/Encrypted_patient2.jpg" alt="Patient Image">
        </div>
        <div class="right">
            <div class="patient-info">
                <h2>患者信息</h2>
                <table>
                    <tr>
                        <th>项目</th>
                        <th>信息</th>
                    </tr>
                    <tr>
                        <td>姓名:</td>
                        <td><span id="patient-name">****</span></td>
                    </tr>
                    <tr>
                        <td>性别:</td>
                        <td><span id="patient-gender">**</span></td>
                    </tr>
                    <tr>
                        <td>年龄:</td>
                        <td><span id="patient-age">**</span></td>
                    </tr>
                    <tr>
                        <td>病况:</td>
                        <td><span id="patient-condition">********</span></td>
                    </tr>
                </table>
                <div id="upload-message" style="margin-top: 10px;"></div>
            </div>
            <div class="edit-buttons">
                <input type="text" id="encrypted-rounds" placeholder="加密后的轮数"><br>
                <input type="text" id="decryption-key" placeholder="解密密钥"><br>
                <button class="edit-button" onclick="decryptPatientImage()">解密患者影像</button>
            </div>
        </div>
    </div>

    <script>
        function decryptPatientImage() {
            const encryptedRounds = document.getElementById("encrypted-rounds").value;
            const decryptionKey = document.getElementById("decryption-key").value;

            const formData = new FormData();
            formData.append('encrypted_rounds', encryptedRounds);
            formData.append('key', decryptionKey);

            fetch('/decrypt_image_patient2', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.error) {
                    alert(data.error);
                } else {
                    const decryptedImage = data.decrypted_image;
                    const imageUrl = 'data:image/jpeg;base64,' + decryptedImage;
                    document.getElementById("patient-image").src = imageUrl;

                    document.getElementById("patient-name").textContent = data.patient_name;
                    document.getElementById("patient-gender").textContent = data.patient_gender;
                    document.getElementById("patient-age").textContent = data.patient_age;
                    document.getElementById("patient-condition").textContent = data.patient_condition;

                    // 输出解密后的轮数到控制台
                    console.log("Decrypted Rounds:", data.decrypted_rounds);
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }

        window.onload = function() {
            const placeholderImageUrl = '/static/Encrypted_patient2.jpg';
            document.getElementById("patient-image").src = placeholderImageUrl;
        };
    </script>
</body>
</html>